package com.shop.admin.service.impl;

import com.shop.Result.LdbzResult;
import com.shop.admin.service.AdminIndexRecommmendAdService;
import com.shop.api.feign.IndexRecommendAdFeign;
import com.shop.pojo.LdbzIndexRecommendAd;
import io.seata.spring.annotation.GlobalTransactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@GlobalTransactional
public class AdminIndexRecommendAdServiceImpl implements AdminIndexRecommmendAdService {

    private static final Logger logger = LoggerFactory.getLogger(AdminIndexRecommendAdServiceImpl.class);

    @Autowired
    private IndexRecommendAdFeign indexRecommendAdFeign;

    @Override
    public LdbzResult selectByKey(Long id) {
        return LdbzResult.ok(indexRecommendAdFeign.selectByKey(id));
    }

    @Override
    public LdbzResult countIndexRecommendAd(LdbzIndexRecommendAd entity) {
        return LdbzResult.ok(indexRecommendAdFeign.countByEntity(entity));
    }

    @Override
    public LdbzResult getIndexRecommendAdPage(LdbzIndexRecommendAd entity, int pn, int limit) {
        Map<String,Object> map = new HashMap();
        long l = indexRecommendAdFeign.countByEntity(entity);
        map.put("total",l);
        if (l>0&&pn>0){
            int start = (pn-1)*limit;
            List<LdbzIndexRecommendAd> indexRecommendAdPage = indexRecommendAdFeign.getIndexRecommendAdPage(entity, start, limit);
            map.put("list",indexRecommendAdPage);
        }
        return LdbzResult.build(0,"",map);
    }

    @Override
    public LdbzResult updateByKey(LdbzIndexRecommendAd entity) {
        return LdbzResult.ok(indexRecommendAdFeign.updateByKey(entity));
    }
}
